﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace xDOMv1.PRE
{
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        DAL.xDOMv1DataContext lsDb;

        public frmMain()
        {
            InitializeComponent();
            this.lsDb = new DAL.xDOMv1DataContext();
        }

        private void barBtnThoat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void barBtnCauHinh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new PRE.frmConfig().ShowDialog();
        }

        private void barBtnDangNhap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barBtnDangNhap.Caption = "Đăng &xuất";
        }

        private void navBarDanhSachPhong_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_Rooms
                                      select new
                                      {
                                          s.Name,
                                          TypeName = s.tb_RoomType.Name,
                                          s.Capacity,
                                          s.ComingDate,
                                          s.ElectricNo,
                                          s.WaterNo,
                                          Status = s.tb_Status.Name
                                      };
            gridView1.ViewCaption = navBarDanhSachPhong.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Tên";
            gridView1.Columns[1].Caption = "Loại";
            gridView1.Columns[2].Caption = "Sức chứa";
            gridView1.Columns[3].Caption = "Ngày đến";
            gridView1.Columns[4].Caption = "Số điện";
            gridView1.Columns[5].Caption = "Số nước";
            gridView1.Columns[6].Caption = "Tình trạng";
        }

        private void navBarLoaiPhong_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_RoomTypes
                                      select s.Name;
            gridView1.ViewCaption = navBarLoaiPhong.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Tên";
        }

        private void navBarDanhSachKhach_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_Guests
                                      select new
                                      {
                                          s.Name,
                                          s.Birthday,
                                          s.Address,
                                          s.MobilePhone,
                                          s.Telephone,
                                          s.Sex,
                                          s.Photo,
                                          Room = s.tb_Room.Name,
                                          s.Note
                                      };
            gridView1.ViewCaption = navBarDanhSachKhach.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Họ tên";
            gridView1.Columns[1].Caption = "Ngày sinh";
            gridView1.Columns[2].Caption = "Địa chỉ";
            gridView1.Columns[3].Caption = "Di động";
            gridView1.Columns[4].Caption = "Điện thoại";
            gridView1.Columns[5].Caption = "Giới tính";
            gridView1.Columns[6].Caption = "Hình";
            gridView1.Columns[7].Caption = "Phòng";
            gridView1.Columns[8].Caption = "Ghi chú";
        }

        private void navBarTinhTrang_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_Status
                                      select s.Name;
            gridView1.ViewCaption = navBarTinhTrang.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Tên";
        }

        private void navBarGiaDienNuoc_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_Fees
                                      select new
                                      {
                                          s.Name,
                                          s.Cost
                                      };
            gridView1.ViewCaption = navBarGiaDienNuoc.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Tên";
            gridView1.Columns[1].Caption = "Giá";
        }

        private void navBarDanhSachHoaDon_LinkPressed(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            gridView1.Columns.Clear();
            gridControl1.DataSource = from s in this.lsDb.tb_Receipts
                                      select new
                                      {
                                          s.Id,
                                          Name = s.tb_Room.Name,
                                          s.RoomFee,
                                          s.ElectricFee,
                                          s.WaterFee,
                                          s.OtherFee,
                                          Sum = s.RoomFee + s.ElectricFee + s.WaterFee + s.OtherFee,
                                          s.Debt,
                                          Status = s.tb_ReceiptStatus.Name,
                                          s.Date,
                                          s.Note
                                      };
            gridView1.ViewCaption = navBarDanhSachHoaDon.Caption.ToUpper();
            gridView1.Columns[0].Caption = "Mã HD";
            gridView1.Columns[1].Caption = "Phòng";
            gridView1.Columns[2].Caption = "Tiền phòng";
            gridView1.Columns[3].Caption = "Tiền điện";
            gridView1.Columns[4].Caption = "Tiền nước";
            gridView1.Columns[5].Caption = "Chi phí khác";
            gridView1.Columns[6].Caption = "Tổng cộng";
            gridView1.Columns[7].Caption = "Nợ";
            gridView1.Columns[8].Caption = "Tình trạng";
            gridView1.Columns[9].Caption = "Tháng";
            gridView1.Columns[10].Caption = "Ghi chú";
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //this.navBarDanhSachHoaDon_LinkPressed(this, null);
            MessageBox.Show(UTL.BaseUTL.PrintInfo());
        }
    }
}